package com.longxi.tianjintianbao.ui.adapter.multitype;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.listener.RectificationListListener;
import com.longxi.tianjintianbao.model.rectification.RectificationList;

import me.drakeet.multitype.ItemViewBinder;

/**
 * Created by cxw on 2018/2/20.
 */
public class RectificationListViewBinder extends ItemViewBinder<RectificationList, RectificationListViewBinder.ViewHolder> {

    RectificationListListener listener;

    public RectificationListViewBinder(RectificationListListener listener) {
        this.listener = listener;
    }

    @NonNull
    @Override
    protected ViewHolder onCreateViewHolder(@NonNull LayoutInflater inflater, @NonNull ViewGroup parent) {
        View root = inflater.inflate(R.layout.item_rectification_list, parent, false);
        return new ViewHolder(root);
    }

    @Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, @NonNull RectificationList rectificationList) {
        holder.mTvInspector.setText("巡检员-" + rectificationList.getPerson());
        holder.mTvState.setText(rectificationList.getState());
        holder.mTvItemStandard.setText("整改小区:" + rectificationList.getBuildname() + "-单号:" + rectificationList.getBillno());
        holder.mTvReason.setText("提交时间：" + rectificationList.getMakedate() + "\n" + "完成时间：" + rectificationList.getLastdate());

        holder.mLlBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                if("未整改".equals(rectificationList.getState())){
//                    listener.onSuccess(rectificationList.getBillid());
//                }
                listener.onSuccess(rectificationList);
            }
        });
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        LinearLayout mLlBtn;
        TextView mTvInspector;
        TextView mTvDate;
        TextView mTvState;
        TextView mTvItemStandard;
        TextView mTvReason;
        ViewHolder(View itemView) {
            super(itemView);
            mLlBtn = itemView.findViewById(R.id.llBtn);
            mTvInspector = itemView.findViewById(R.id.tvInspector);
            mTvDate = itemView.findViewById(R.id.tvDate);
            mTvState = itemView.findViewById(R.id.tvState);
            mTvItemStandard = itemView.findViewById(R.id.tvItemStandard);
            mTvReason = itemView.findViewById(R.id.tvReason);
        }
    }
}
